package com.chenya.service;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <h1> </h1>
 *
 * @author 90后野生程序猿
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2021/7/6 5:12 PM
 */
@Service("userDetailsService")
public class MyUserDetailService implements UserDetailsService {

    /**
     * <h2>重写用户名密码登录</h2>
     * @param s
     * @return
     * @throws UsernameNotFoundException
     */
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        List<GrantedAuthority> grantedAuthorityList = AuthorityUtils.commaSeparatedStringToAuthorityList("admin");
        return new User("mary",new BCryptPasswordEncoder().encode("123"),grantedAuthorityList);
    }
}
